package br.com.news.ws;

import java.util.List;
import br.com.news.utils.beans.BaseBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


public abstract class GenericWs<T extends BaseBean> {

	public List<BaseBean> convertListFromJson(String json) {
		Gson gson = new Gson();
		return gson.fromJson(json, new TypeToken<List<T>>(){}.getType());
	}

	public BaseBean convertFromJson(String json,BaseBean base) {
		Gson gson = new Gson();
		return gson.fromJson(json, base.getClass());
	}

	public String listToJson(List<T> base) {
		Gson gson = new Gson();
		return gson.toJson(base);
	}

	public String toJson(T base) {
		Gson gson = new Gson();
		return gson.toJson(base);
	}

	public String booleanToJson(Boolean bool) {
		Gson gson = new Gson();
		return gson.toJson(bool);
	}
	
	public String toJson(Long inteiro) {
		Gson gson = new Gson();
		return gson.toJson(inteiro);
	}


}
